package com.ruoyi.web.controller.emergencyplan;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.pengjie.SnowflakeIdUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.emergencyplan.domain.EpResourceMaterialManage;
import com.ruoyi.emergencyplan.service.IEpResourceMaterialManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 应急资源——物资管理Controller
 * 
 * @author hcc
 * @date 2023-12-17
 */
@RestController
@RequestMapping("/emergencyplan/materialManage")
public class EpResourceMaterialManageController extends BaseController
{
    @Autowired
    private IEpResourceMaterialManageService epResourceMaterialManageService;

    /**
     * 查询应急资源——物资管理列表
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:materialManage:list')")
    @GetMapping("/list")
    public TableDataInfo list(EpResourceMaterialManage epResourceMaterialManage)
    {
        startPage();
        List<EpResourceMaterialManage> list = epResourceMaterialManageService.selectEpResourceMaterialManageList(epResourceMaterialManage);
        return getDataTable(list);
    }

    /**
     * 导出应急资源——物资管理列表
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:materialManage:export')")
    @Log(title = "应急资源——物资管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EpResourceMaterialManage epResourceMaterialManage)
    {
        List<EpResourceMaterialManage> list = epResourceMaterialManageService.selectEpResourceMaterialManageList(epResourceMaterialManage);
        ExcelUtil<EpResourceMaterialManage> util = new ExcelUtil<EpResourceMaterialManage>(EpResourceMaterialManage.class);
        util.exportExcel(response, list, "应急资源——物资管理数据");
    }

    /**
     * 获取应急资源——物资管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:materialManage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(epResourceMaterialManageService.selectEpResourceMaterialManageById(id));
    }

    /**
     * 新增应急资源——物资管理
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:materialManage:add')")
    @Log(title = "应急资源——物资管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EpResourceMaterialManage epResourceMaterialManage)
    {
        epResourceMaterialManage.setId(String.valueOf(new SnowflakeIdUtils(5,8).nextId()));
        return toAjax(epResourceMaterialManageService.insertEpResourceMaterialManage(epResourceMaterialManage));
    }

    /**
     * 修改应急资源——物资管理
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:materialManage:edit')")
    @Log(title = "应急资源——物资管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EpResourceMaterialManage epResourceMaterialManage)
    {
        return toAjax(epResourceMaterialManageService.updateEpResourceMaterialManage(epResourceMaterialManage));
    }

    /**
     * 删除应急资源——物资管理
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:materialManage:remove')")
    @Log(title = "应急资源——物资管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(epResourceMaterialManageService.deleteEpResourceMaterialManageByIds(ids));
    }
}
